# @Version : 1.0
# @Author  : wxz
# @File    : chat_message_dao.py
# @Time    : 2025/6/20 21:11
# @Describe: 描述...

from fastapi import Depends
from sqlmodel import Session, select

from apps.chat.data_model.chat_message_model import ChatMessageModel
from database.mysql.mysql_client import MySQLClient


class ChatMessageDao:

    def __init__(self, db_session: Session = Depends(MySQLClient.get_db_session) ):
        self.db_session = db_session


    def find_by_user_chat_id(self, user_id: str, user_chat_id: str)-> list[ChatMessageModel] | None:

        stmt = (select(ChatMessageModel)
                .where(ChatMessageModel.user_id == user_id)
                .where(ChatMessageModel.user_chat_id == user_chat_id)
                .where(ChatMessageModel.is_delete == 0)
                .order_by(ChatMessageModel.create_time)
                )

        chat_message_lst = self.db_session.exec(stmt).all()

        return chat_message_lst

    def save_all(self, chat_message_lst: list[ChatMessageModel])-> None:
        self.db_session.add_all(chat_message_lst)
        self.db_session.flush()














